package lol.clann.minecraft.springboot.plugin.bukkit.listener;

import lol.clann.minecraft.springboot.api.bukkit.event.PlayerChangeChunkEvent;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.springframework.stereotype.Service;

/**
 *
 * @author pyz
 * @date 2019/6/22 10:31 AM
 */
@Service
public class AdapterListener implements Listener {
    /**
     * 发布玩家跨区块事件
     * @param event
     */
    @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
    private void onMove(PlayerMoveEvent event) {
        if (event.getFrom().getChunk() != event.getTo().getChunk()) {
            PlayerChangeChunkEvent e = new PlayerChangeChunkEvent(event.getPlayer(), event.getFrom().getChunk(), event.getTo().getChunk());
            Bukkit.getPluginManager().callEvent(e);
            if (e.isCancelled()) {
                event.setCancelled(true);
            }
        }
    }
}
